<template>
  <div>
    <div>
      <FilterTable
        ref="orderTable"
        :columns="columnsList"
        columnsRef="partPartInventoryAdjustInventorySearchAllocateInOrderPage"
        :fetchapi="getTableData"
        :params="fetchParams"
        :datakey="'rows'"
        :onColumnsChange="columns => (this.columnsList = columns)"
        :height="'200'"
        selectionType="single"
        :onRowSelectChange="selectRow"
      ></FilterTable>
    </div>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button type="primary" @click="closeDialog(2)">确 认</el-button>
      <el-button @click="closeDialog(1)">取 消</el-button>
    </div>
  </div>
</template>

<script>
import { getOrderData } from '@/api/part/partInventory/adjustInventory/index';
import { dictionary } from '@/utils/dictMixin';
import { getAllUser } from '@/api/customerRepair/afterSaleVisit/resultEntry';
export default {
  name: 'searchInOrderPage',
  mixins: [dictionary],
  props: ['orderNo', 'ptype'],
  data() {
    return {
      columnsList: this.createTableColumns(),
      getTableData: getOrderData,
      selectRowData: {},
      serviceAdvisorData: [],
      fetchParams: {
        allocateInNo: this.orderNo,
        xhrAbort: true
      }
    };
  },
  created() {
    this.fetchParams = Object.assign(this.fetchParams, {
      xhrAbort: false,
      ptype: this.ptype
    });
  },
  mounted() {
    this.getQueryBookingInformation();
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        { title: '借进入库单号', dataIndex: 'ALLOCATE_IN_NO', sorter: true, filter: true, filterType: 'input', showOverflowTooltip: true },
        { title: '供应商代码', dataIndex: 'CUSTOMER_CODE', sorter: true, filter: true, filterType: 'input', showOverflowTooltip: true },
        { title: '供应商名称', dataIndex: 'CUSTOMER_NAME', sorter: true, filter: true, filterType: 'input', showOverflowTooltip: true },
        { title: '入库日期', dataIndex: 'STOCK_IN_DATE', dateFormat: 'yyyy-MM-dd', sorter: true, filter: true, filterType: 'input', showOverflowTooltip: true },
        {
          title: '经手人',
          dataIndex: 'HANDLER',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.getEmployeeName(props.row.HANDLER)}</span>;
          }
        },
        {
          title: '锁定人',
          dataIndex: 'LOCK_USER',
          sorter: true,
          filter: true,
          filterType: 'input',
          render: props => {
            return <span>{this.getEmployeeName(props.row.LOCK_USER)}</span>;
          }
        }
      ];
    },
    async getQueryBookingInformation() {
      let res = await getAllUser();
      this.serviceAdvisorData = res.data.map(x => ({ text: x.employeeName, value: x.userId }));
    },
    getEmployeeName(userId) {
      const item = this.serviceAdvisorData.find(x => {
        return x.value == userId;
      });
      return item ? item.text : '';
    },
    FormPanelSeacher() {
      this.$refs.formPanel.SUBMIT_FORM();
    },
    formchangeFun(val) {
      this.fetchParams = Object.assign({}, this.fetchParams, val, { xhrAbort: false });
    },
    selectRow(row) {
      this.selectRowData = row;
    },
    confirmFun() {},
    closeDialog(param) {
      if (param == 1) {
        this.$emit('close', false, param);
      } else {
        if (!this.selectRowData.length) {
          this.$notify({ title: '警告信息', message: '请选择需要添加的记录！', type: 'warning' });
          return;
        }
        this.$emit('showOrder', this.selectRowData);
        this.closeDialog(1);
      }
    }
  }
};
</script>

<style lang="less" scoped></style>
